package com.fxhy.utils;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.UUID;

public class UuidUtil {

	public static String get32UUID() {
		String uuid = UUID.randomUUID().toString().trim().replaceAll("-", "");
		return uuid;
	}
	
	public static String getOrderIdByUUId(Integer userId) {

	    int hashCodeV = UUID.randomUUID().toString().hashCode();
	    if (hashCodeV < 0) {//有可能是负数
	        hashCodeV = -hashCodeV;
	    }
	    // 0 代表前面补充0
	    // 4 代表长度为4
	    // d 代表参数为正数型
	    String orderId= userId + String.format("%015d", hashCodeV);
	    return orderId;
	}
	
	public static String genId(Integer userId){
	    String orderId =
	                    (DateUtils.getNowDate() + "").substring(1) +
	                    (System.nanoTime() + "").substring(7, 10)+
	                    userId;
	    return orderId;
	}
	
	private static long orderNum = 0l;  
    private static String date ;
	/** 
     * 生成订单编号 
     * @return 
     */  
    public static synchronized String getOrderNo() {  
        String str = new SimpleDateFormat("yyMMddHHmm").format(new Date());  
        if(date==null||!date.equals(str)){  
            date = str;  
            orderNum  = 0l;  
        }  
        orderNum ++;  
        long orderNo = Long.parseLong((date)) * 10000;  
        orderNo += orderNum;;  
        return orderNo+"";  
    }  

//    public static void main(String[] args) {
////		System.out.println(get32UUID());
////		System.out.println(getOrderIdByUUId(217));
//		System.out.println(genId(217));
////    	System.out.println(getOrderNo());
//	}
}

